package org.example.reemploymentsys.controller;

import org.example.reemploymentsys.entity.Organization;
import org.example.reemploymentsys.entity.UserTb;
import org.example.reemploymentsys.repository.OrganizationRe;
import org.example.reemploymentsys.repository.UserTbRe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

@RestController
public class InstitutionController {
    @Autowired
    private UserTbRe userTbRe;
    @Autowired
    private OrganizationRe organizationRe;
    @PostMapping("/getInstInfo")
    public Organization createInstitution(@RequestBody String username) {
        System.out.println(username);
        String name= username.replace("\"","").replace("\"","");
        System.out.println(name);
        String OrganizationId= userTbRe.findOrgizationIdByUsername(name);
        System.out.println(OrganizationId);
        System.out.println(organizationRe.findOrganizationById(OrganizationId));
        return organizationRe.findOrganizationById(OrganizationId);
    }
    @PostMapping("/updateInstitution")
    public void updateInstitution(@RequestBody Organization organization) {
        System.out.println(organization);
        organizationRe.save(organization);
    }
    @PostMapping("/getInstAdmins")
    public List<UserTb> getInstAdmin(@RequestBody String username) {
        System.out.println(username);
        String name= username.replace("\"","").replace("\"","");
        System.out.println(name);
        String OrganizationId= userTbRe.findOrgizationIdByUsername(name);
        System.out.println(OrganizationId);
        System.out.println(userTbRe.findUserByOrgId(OrganizationId));
        return userTbRe.findUserByOrgId(OrganizationId);

    }
    @PostMapping("/getUserInfo")
    public UserTb getUserInfo(@RequestBody String username) {
        System.out.println(username);
        String name= username.replace("\"","").replace("\"","");
        System.out.println(name);
        return userTbRe.findUserByUsername(name);
    }
}
